// pages/recharge/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        balance: 0,
        defaultButtons: [
            {
                type: 'primary',
                money: 500
            },
            {
                type: 'warn',
                money: 1000
            },
            {
                type: 'primary',
                money: 1500
            },
            {
                type: 'warn',
                money: 2000
            },
            {
                type: 'default',
                money: 5000
            }
        ]

    },

    handleClick(e) {
        const money = e.currentTarget.dataset.money;
        this.setData({ money })
    },
    handleReset() {
        this.setData({ money: '' })
    },
    handleSubmit() {
        const money = this.data.money + this.data.balance;
        if (this.data.money) {
            wx.redirectTo({
                url: '/pages/index/index?money=' + money,
                success() {
                    wx.showToast({
                        title: '充值成功',
                        icon: 'success',
                    })
                }
            })
        } else {
            wx.showToast({
                title: '请输入充值金额',
                icon: 'error',
            })
        }
    },
    onLoad(options) {
        if (options) {
            this.setData({balance : options.balance ? parseInt(options.balance) : 0})
        }
    }

})